<!--
 * @Author: liangzhuo liangzhuo@chzu.com
 * @Date: 2022-05-07 15:38:27
 * @LastEditors: liangzhuo liangzhuo@chzu.com
 * @LastEditTime: 2022-05-07 15:53:32
 * @FilePath: \ruoyi-ui\src\components\DataDetails\typeOfPig.vue
 * @Description: 爬山猪的种类
-->
<template>
  <div
    :class="className"
    ref="chartDiv"
    :style="{ height: height, width: width }"
  />
</template>

<script>
import echarts from "echarts";
require("echarts/theme/macarons"); // echarts theme
import resize from "@/views/dashboard/mixins/resize.js";

const animationDuration = 6000;

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: "chart",
    },
    width: {
      type: String,
      default: "100%",
    },
    height: {
      type: String,
      default: "100%",
    },
  },
  data() {
    return {
      chart: null,
    };
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart();
    });
  },
  beforeDestroy() {
    if (!this.chart) {
      return;
    }
    this.chart.dispose();
    this.chart = null;
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, "macarons");
      const size = this.$refs.chartDiv.offsetWidth;
      this.chart.setOption({
        title: {
          show: true,
          text: "已有爬山猪的品种",
          textStyle: {
            fontFamily: "MicrosoftYaHei",
            color: '#000',
            fontSize: size / 50,
          },
          padding: 0,
          top: 10,
          left: size / 50,
        },
        color: [
          "#37a2da",
          "#32c5e9",
          "#9fe6b8",
          "#ffdb5c",
          "#ff9f7f",
          "#fb7293",
          "#e7bcf3",
          "#8378ea",
        ],
        tooltip: {
          trigger: "item",
          formatter: "{a} <br/>{b} : {c} ({d}%)",
        },
        toolbox: {
          show: true,
        },
        legend: {
          x: "70%", //水平位置，【left\center\right\数字】
          y: "100", //垂直位置，【top\center\bottom\数字】
          align: "left", //字在图例的左边或右边【left/right】
          orient: "vertical", //图例方向【horizontal/vertical】
          icon: "circle", //图例形状【circle\rect\roundRect\triangle\diamond\pin\arrow\none】
          textStyle: {
            color: "#8C8C8C",
          },
          // height:150
        },
        series: [
          {
            name: "业务警种",
            type: "pie",
            radius: ["0%", "70%"],
            center: ["40%", "50%"],
            data: [
              { value: 20, name: "国宝" },
              { value: 30, name: "治安" },
              { value: 25, name: "城市3" },
              { value: 25, name: "城市4" },
              { value: 20, name: "城市5" },
              { value: 35, name: "城市6" },
              { value: 30, name: "城市7" },
              { value: 40, name: "城市8" },
              { value: 25, name: "城市9" },
              { value: 25, name: "城市10" },
            ],
          },
        ],
      });
    },
  },
};
</script>
